<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>getElementsByTagName</title>
    <script type="text/javascript">
        function getElements(){
            var input1 = document.getElementById("input1");
            //获取所有img集合对象
            var imgs = document.getElementsByTagName("img");
            if (input1.value == "查看多少小猫,并切换成小狗") {
                for (var i = 0; i < imgs.length; i++) {
                    imgs[i].src = (i + 4) + ".png";
                }
                input1.value = "查看多少小狗,并切换成小猫";
            }else if(input1.value == "查看多少小狗,并切换成小猫"){
                for (var i = 0; i < imgs.length; i++) {
                    imgs[i].src =  (i+1) + ".png";
                }
                input1.value = "查看多少小猫,并切换成小狗";
            }
        }
    </script>
</head>
<body>
<img src="1.png" height="100">
<img src="2.png" height="100">
<img src="3.png" height="100">
<br/>
<input id="input1" type="button" onclick="getElements()" value="查看多少小猫,并切换成小狗">
</body>
</html>